<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button type="primary" @click="handleCreate">新建核定表</el-button>
    </div>

    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column label="ID" align="center" width="95">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      
      <el-table-column label="部门" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.department }}
        </template>
      </el-table-column>
      
      <el-table-column label="岗位" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.position }}
        </template>
      </el-table-column>
      
      <el-table-column label="面试时间" width="150" align="center">
        <template slot-scope="scope">
          {{ scope.row.interviewTime }}
        </template>
      </el-table-column>
      
      <el-table-column label="报到时间" width="150" align="center">
        <template slot-scope="scope">
          {{ scope.row.reportTime }}
        </template>
      </el-table-column>
      
      <el-table-column label="操作" align="center" width="230" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="handleUpdate(row)">
            编辑
          </el-button>
          <el-button size="mini" type="danger" @click="handleDelete(row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getEmployeeVerificationList, deleteEmployeeVerification } from '@/api/employeeVerification'
import Pagination from '@/components/Pagination'

export default {
  components: { Pagination },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        current: 1,
        size: 10
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      this.listLoading = true
      try {
        const response = await getEmployeeVerificationList(this.listQuery)
        this.list = response.records
        this.total = response.total
      } catch (error) {
        console.error('获取列表失败:', error)
      }
      this.listLoading = false
    },
    handleCreate() {
      this.$router.push('/biao/heding')
    },
    handleUpdate(row) {
      this.$router.push(`/biao/heding?id=${row.id}`)
    },
    async handleDelete(row) {
      try {
        await this.$confirm('确认删除该记录吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        await deleteEmployeeVerification(row.id)
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
        this.getList()
      } catch(error) {
        console.error('删除失败:', error)
      }
    }
  }
}
</script>

<style scoped>
.filter-container {
  padding-bottom: 10px;
}
</style> 